const Controller = require('../../controllers/controllers.js').controller;
Component({
  /**
   * 组件的属性列表
   */
  properties: {
        visible:{
          type:Boolean,
          value:false
        },
        type:{
          type:Number,
          value:1
        },
        zindex:{
          type:Number,
          value:9990
        }
  },

  /**
   * 组件的初始数据
   */
  data: {
    form: {
      imageUrl:'',
      title:'新版本抢先体验',
      desc: "气和到受容状子题得治高共育今即次求志拉但提天日后越相根合特外斗还知每直来证可常文非信习活设转次习山已空需切。面许打会也比京料音中气和到受容状子题得治高共育今即次求志拉但提天日后越相根合特外斗还知每直来证可常文非信习活设转次习山已空需切。面许打会也比京料音中 "
    }
  },
  pageLifetimes: {
    show: function() {
      // 页面被展示
    },
    hide: function() {
      // 页面被隐藏
      // this.setData({
      //     visible:false
      // })
    },
    resize: function(size) {
      // 页面尺寸变化
    }
  },
  

  ready(){
     
  
    
  if(this.data.type==1){
    this.noticeAction()
  }
  if(this.data.type==2){
    this.signAction()
  }

  
  
    
  
    

  },

 

  /**
   * 组件的方法列表
   */
  methods: {
   close(){
     
     this.setData({
       visible:false
     },()=>{
       if(this.data.type==2){
           this.signAction()
       }
     })
   },
   getTime(){
     
 

    let date=new Date()
    let y = date.getFullYear()
    let m=date.getMonth()+1>=10?date.getMonth()+1:'0'+(date.getMonth()+1)
    let d=date.getDate()>=10?date.getDate():'0'+date.getDate()

    let end=`${y}-${m}-${d} 23:59:59`

    if (/(iPhone|iPad|iPod|iOS)/i.test(wx.getStorageSync('modelmes'))) {
      //ios
      end = new Date(end.replace(/-/g, "/")).getTime()
  
    }


    return end
    
  
    

    
         

  },
   noticeAction(){
     let that=this
    Controller.notice({}).then(res=>{
       
      if(res.code==0){
        let baseData=res.data.baseData

        if(baseData){
         
  
         
          if(wx.getStorageSync('noticeTime')){
             let isPass=new Date().getTime()-wx.getStorageSync('noticeTime')>0?true:false
             console.log('目前时间',new Date().getTime())
             console.log('当天时间',wx.getStorageSync('noticeTime'))
             console.log('isPass',isPass)
            if(isPass){
               
              that.setData({
                visible:true,
                form:baseData,
                type:1
              },()=>{
                wx.setStorageSync('noticeTime',that.getTime())
              })
              
            }else{
              that.setData({
                visible:false
               })
            }
            
            
          }else{
           
            that.setData({
              visible:true,
              form:baseData,
              type:1
            },()=>{
          
              wx.setStorageSync('noticeTime',that.getTime())
            })  
          }
        }
      }
     
    })
  },
  
  signAction(){
  let that=this
    Controller.signInfo({}).then(res=>{
      
      if(res.code==0){
        let baseData=res.data.baseData
        if(baseData){
         
          if(wx.getStorageSync('signTime')){
              let isPass=new Date().getTime()-wx.getStorageSync('signTime')>0?true:false
            if(isPass){
               
              that.setData({
                  visible:true,
                  form:baseData,
                  type:2
              },()=>{
                wx.setStorageSync('signTime', that.getTime())
              })
              
            }else{
              that.setData({
                visible:false
               })
            }
            
          }else{
           
            that.setData({
              visible:true,
              form:baseData,
              type:2
            },()=>{
              wx.setStorageSync('signTime',that.getTime())
            })  
          }
        }
      }
     
    })
  },
  goLink(e){
    let url=e.currentTarget.dataset.url
   
    if(url){
      this.setData({
        visible:false
      },()=>{
        wx.navigateTo({
          url
        })
      })
     
    }
  }
  }
})